package com.vic.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.SneakyThrows;

/**
 * rabbitmq工具类
 */
public class RabbitmqUtils {

    @SneakyThrows
    public static Channel getChannel() {
        ConnectionFactory factory = new ConnectionFactory();
        // 主机
        factory.setHost("10.61.100.78");
        // 端口，对应/etc/rabbitmq/rabbitmq.conf文件中配置的端口
        factory.setPort(5673);
        // 用户名
        factory.setUsername("root");
        // 密码
        factory.setPassword("root");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        return channel;
    }

    @SneakyThrows
    public static Connection getConn() {
        ConnectionFactory factory = new ConnectionFactory();
        // 主机
        factory.setHost("10.61.100.78");
        // 端口，对应/etc/rabbitmq/rabbitmq.conf文件中配置的端口
        factory.setPort(5673);
        // 用户名
        factory.setUsername("root");
        // 密码
        factory.setPassword("root");

        Connection connection = factory.newConnection();
        return connection;
    }

}
